package com.gt.wifimanager.util;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;

import com.gt.wifimanager.R;

public class ItemUtil {
	
	private static ProgressDialog progressDialog;
	
	public static ProgressDialog showLoading(Context context){
		
		if(progressDialog==null){
			progressDialog = new ProgressDialog(context);
			progressDialog.setTitle(R.string.app_name);
			progressDialog.setMessage(context.getString(R.string.str_loading));
			progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		}
		
		progressDialog.show();
		return progressDialog;
	}
	
	public static void closeLoading(){
		if(progressDialog!=null){
			progressDialog.hide();
			progressDialog.cancel();
			progressDialog = null;
		}
	}
	
	public static void showAlert(Context context, String text){
		closeLoading();
		
		Dialog dialog = new AlertDialog.Builder(context)
        .setIcon(android.R.drawable.stat_notify_error)
        .setTitle(R.string.app_name)
        .setMessage(text)
        .setNeutralButton(R.string.str_close, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface d, int whichButton) {
            	d.cancel();
            }
        })
        .create();
        dialog.show();
	}
	
}
